package com.example.demofdfs.example.queue;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class TaskDelayed implements Delayed {
	
	// 任务
	private Task task;
	
	public TaskDelayed(Task task) {
		super();
		this.task = task;
	}
	
	public Task getTask() {
		return task;
	}

	@Override
	public int compareTo(Delayed o) {
		return (int) (this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
	}

	@Override
	public long getDelay(TimeUnit unit) {
		long time = task.getTime();
		long currentTime = System.currentTimeMillis();
		return unit.convert(time - currentTime, TimeUnit.MILLISECONDS);
	}
	
}
